Skip to content

Move typing imports under TYPE_CHECKING block - #9827

Open
hugovk wants to merge 3 commits into
python-pillow:mainfrom
hugovk:flake8-type-checking
Open

Move typing imports under TYPE_CHECKING block#9827
hugovk wants to merge 3 commits into
python-pillow:mainfrom
hugovk:flake8-type-checking

Conversation

@hugovk

@hugovk hugovk commented Jul 26, 2026

Copy link
Copy Markdown
Member

Use https://docs.astral.sh/ruff/rules/#flake8-type-checking-tc so we only import typing things when checking types.

Comment thread src/PIL/Image.py
factor_y = int((box[3] - box[1]) / size[1] / reducing_gap) or 1
if factor_x > 1 or factor_y > 1:
reduce_box = self._get_safe_box(size, cast(Resampling, resample), box)
reduce_box = self._get_safe_box(size, cast("Resampling", resample), box)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this get changed just for consistency? (Resampling is defined in this file.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check. That wasn't clear from the commit/PR message. I didn't scroll down far enough to see that all of TC got enabled :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could ignore TC006, skip it for this line, or leave it be. I don't mind really.

Comment thread src/PIL/Image.py Outdated
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants